// Angular Version 6 below need to be deleted {providedIn: 'root'}

// angular
import {Injectable} from '@angular/core';
import {HttpParams} from '@angular/common/http';
// owner
import {Request} from 'pengesoft-ng-lib';
// models
import {CheckOutApplyList, CheckOutApply} from '../domains/CheckOutApply.domain';
import {Map} from '../domains/map.domain';

/**
 *
 */
@Injectable({
  providedIn: 'root'
})
export class CheckOutApplyServiceSvr {
  private readonly baseUrl: string;

  constructor(
    private request: Request
  ) {
    this.baseUrl = 'checkOutApplyServiceSvr.assx/';
  }


  updateCheckOutApplyState(token: string, checkOutApplyId: string, state: number): Promise<Map> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('checkOutApplyId', checkOutApplyId.toString())
      .append('state', state.toString());
    return this.request.post<Map>(this.baseUrl + 'updateCheckOutApplyState', httpParams).then((res) => {
      return new Map(res);
    });
  }


  saveCheckOutApply(token: string, customerId: string, contractId: string): Promise<CheckOutApply> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('customerId', customerId.toString())
      .append('contractId', contractId.toString());
    return this.request.post<CheckOutApply>(this.baseUrl + 'saveCheckOutApply', httpParams).then((res) => {
      return new CheckOutApply(res);
    });
  }


  getCheckOutApplyByContractId(token: string, contractId: string): Promise<CheckOutApplyList> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('contractId', contractId.toString());
    return this.request.post<CheckOutApplyList>(this.baseUrl + 'getCheckOutApplyByContractId', httpParams).then((res) => {
      return res;
    });
  }


  getCheckOutApplyByPrimaryKey(token: string, checkOutApplyId: string): Promise<CheckOutApply> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('checkOutApplyId', checkOutApplyId.toString());
    return this.request.post<CheckOutApply>(this.baseUrl + 'getCheckOutApplyByPrimaryKey', httpParams).then((res) => {
      return new CheckOutApply(res);
    });
  }


  GetVersion(): Promise<string> {
    const httpParams = new HttpParams();
    return this.request.post<string>(this.baseUrl + 'GetVersion', httpParams).then((res) => {
      return res;
    });
  }


  listCheckOutApplys(token: string, customerId: string, state: number, startTime: string, endTime: string, pageNum: number, pageCount: number): Promise<CheckOutApplyList> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('customerId', customerId.toString())
      .append('state', state.toString())
      .append('startTime', startTime.toString())
      .append('endTime', endTime.toString())
      .append('pageNum', pageNum.toString())
      .append('pageCount', pageCount.toString());
    return this.request.post<CheckOutApplyList>(this.baseUrl + 'listCheckOutApplys', httpParams).then((res) => {
      return res;
    });
  }


  deleteCheckOutApply(token: string, checkOutApplyId: string): Promise<number> {
    const httpParams = new HttpParams()
      .append('token', token.toString())
      .append('checkOutApplyId', checkOutApplyId.toString());
    return this.request.post<number>(this.baseUrl + 'deleteCheckOutApply', httpParams).then((res) => {
      return res;
    });
  }
}
